import utils from '@/static/js/utils.js';
import config from '@/static/config.js';

const USER_KEY = 'username';
const LANG_KEY = 'lang';

export function getUsername () {
    let username = utils[config.tokenStorage].get(USER_KEY);

    return username;
}
export function setUsername (value) {
    utils[config.tokenStorage].set(USER_KEY, value);
}

// zh-CN、en-US
export function getLangType () {
    let lang = utils[config.tokenStorage].get(LANG_KEY);

    return lang;
}
export function setLangType (value) {
    utils[config.tokenStorage].set(LANG_KEY, value);
}

export function signOut() {
    removeLoginInfo();

    if (!window.location.href.includes(config.loginUrl)) {
        utils.innerReplace(config.loginUrl)
    }
}

export function removeLoginInfo() {
    utils[config.tokenStorage].remove(USER_KEY);
    utils[config.tokenStorage].remove(LANG_KEY);
    utils.localStorage.clear();
    utils.sessionStorage.clear();
}